package com.sixkey.controller;


import com.sixkey.annotation.OperationLog;
import com.sixkey.entity.Sign;
import com.sixkey.entity.vo.SignVo;
import com.sixkey.response.Response;
import com.sixkey.service.ISignService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户签到表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-25
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/sign")
@RequiredArgsConstructor
public class SignController {

    private final ISignService signService;

    /**
     * 分页获取签到数据
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize,
                         SignVo signVo) {
        log.info("分页获取签到数据请求进来");
        Map<String,Object> map = signService.queryList(pageNo,pageSize,signVo);
        return Response.success(map);
    }

    /**
     *
     * @param
     * @return
     */
    @PostMapping("/save")
    public Response saveMessage(@RequestBody SignVo signVo) {
        signService.saveSign(signVo);
        return Response.success();
    }

    /**
     * 修改签到
     * @param sign
     * @return
     */
    @PutMapping("/update")
    @OperationLog("修改签到")
    public Response update(@RequestBody @Valid Sign sign){
        log.info("修改签到请求进来");
        signService.updateSign(sign);
        return Response.success();
    }

    /**
     * 签到数据回显
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getMessageInfo(@PathVariable("id") Integer id){
        log.info("签到数据回显进来");
        SignVo signVo = signService.getSignById(id);
        return Response.success(signVo);
    }

    /**
     * 删除签到
     * @param
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @OperationLog("删除签到")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("删除签到请求进来");
        signService.removeBatchByIds(id);
        return Response.success();
    }
}
